package com.aipanda.entity;

import java.util.ArrayList;
import java.util.List;
import javax.persistence.CollectionTable;
import javax.persistence.Column;
import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.NotEmpty;

/**
 * 会员属性字段类
 * @param name			属性名
 * @param type			类型
 * @param isEnabled		是否启用
 * @param isRequired	是否必填
 * @param propertyIndex	属性序号
 * @param options		可选项[一对多关系->集合表]
 * @author wanyuxiang
 *
 */
@Entity
@Table(name = "aipanda_member_attribute")
public class MemberAttribute extends OrderEntity {
	private static final long serialVersionUID = 4513705276569738136L;
	private String name;
	private Type type;
	private Boolean isEnabled;
	private Boolean isRequired;
	private Integer propertyIndex;
	private List<String> options = new ArrayList<String>();

	/**
	 * <li>name 姓名</li>
	 * <li>gender 性别</li>
	 * <li>birth 出生日期</li>
	 * <li>area 地区</li>
	 * <li>address 地址</li>
	 * <li>zipCode 邮编</li>
	 * <li>phone 电话</li>
	 * <li>mobile 手机</li>
	 * <li>text 文本输入框</li>
	 * <li>select  单选</li>
	 * <li>checkbox 多选</li>
	 * @author wanyuxiang
	 *
	 */
	public enum Type {
		name, gender, birth, area, address, zipCode, phone, mobile, text, select, checkbox;
	}

	@NotEmpty
	@Length(max = 255)
	@Column(nullable = false)
	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@NotNull(groups = { Save.class })
	@Column(name="type",nullable = false, updatable = false)
	public Type getType() {
		return this.type;
	}

	public void setType(Type type) {
		this.type = type;
	}

	@NotNull
	@Column(name="is_enabled",nullable = false)
	public Boolean getIsEnabled() {
		return this.isEnabled;
	}

	public void setIsEnabled(Boolean isEnabled) {
		this.isEnabled = isEnabled;
	}

	@NotNull
	@Column(name="is_required",nullable = false)
	public Boolean getIsRequired() {
		return this.isRequired;
	}

	public void setIsRequired(Boolean isRequired) {
		this.isRequired = isRequired;
	}

	@Column(name="property_index",updatable = false)
	public Integer getPropertyIndex() {
		return this.propertyIndex;
	}

	public void setPropertyIndex(Integer propertyIndex) {
		this.propertyIndex = propertyIndex;
	}
	
	@ElementCollection
	@CollectionTable(name = "aipanda_member_attribute_option",joinColumns = {@JoinColumn(name="member_attribute")})
	@Column(name="options")	
	public List<String> getOptions() {
		return this.options;
	}

	public void setOptions(List<String> options) {
		this.options = options;
	}
}
